package com.fau.cm.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 资费管理表
 * @author liy
 * @datetime 2014年12月10日,下午4:24:08
 */
@Entity
@Table(name = "medical_tariff")
public class MedicalTariff implements Serializable,JSONAware {

	private static final long serialVersionUID = -5587533394521380412L;
	
	private String id;
	
	@NotBlank(message = "标题不能为空！")
	@Length(max = 30, message = "标题长度需要在0和30之间")
	private String title;				// 标题
	
	private String relayName;			// 中继名称
	
	@NotNull(message = "基本资费不能为空！")
	private BigDecimal basicFee;		// 基本资费
	
	private String type;				// 呼叫类型
	private String remark;				// 说明
	@NotNull(message = "起步时长不能为空！")
	private Integer startime;			// 起步时长
	
	private String eid;					// 企业ID
	private MedicalPreferentialPlan preferential;	// 优惠方案
	
	private Date createTime = new Date();
	private Date updateTime = new Date();
	
	private String typeId;
	private String preferentiaId;
	private String relayId;
	private String relayTitle;
	private String typeValue;
	

	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "title", length = 30)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "remark", length = 30)
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "update_time")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	@Column(name = "eid", length = 32)
	public String getEid() {
		return eid;
	}

	public void setEid(String eid) {
		this.eid = eid;
	}

	@Column(name = "basic_fee", length = 7)
	public BigDecimal getBasicFee() {
		return basicFee;
	}

	public void setBasicFee(BigDecimal basicFee) {
		this.basicFee = basicFee;
	}

	@ManyToOne
	@JoinColumn(name = "preferential")
	public MedicalPreferentialPlan getPreferential() {
		return preferential;
	}

	public void setPreferential(MedicalPreferentialPlan preferential) {
		this.preferential = preferential;
	}
	
	@Transient
	public String getTypeId() {
		return typeId;
	}

	public void setTypeId(String typeId) {
		this.typeId = typeId;
	}

	@Transient
	public String getPreferentiaId() {
		return preferentiaId;
	}

	public void setPreferentiaId(String preferentiaId) {
		this.preferentiaId = preferentiaId;
	}

	@Transient
	public String getRelayId() {
		return relayId;
	}

	public void setRelayId(String relayId) {
		this.relayId = relayId;
	}
	
	@Transient
	public String getRelayTitle() {
		return relayTitle;
	}

	public void setRelayTitle(String relayTitle) {
		this.relayTitle = relayTitle;
	}

	@Column(name = "start_time", length = 5)
	public Integer getStartime() {
		return startime;
	}

	public void setStartime(Integer startime) {
		this.startime = startime;
	}

	@Column(name = "type", length = 32)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Transient
	public String getTypeValue() {
		return typeValue;
	}

	public void setTypeValue(String typeValue) {
		this.typeValue = typeValue;
	}

	@Column(name = "relay", length = 32)
	public String getRelayName() {
		return relayName;
	}

	public void setRelayName(String relayName) {
		this.relayName = relayName;
	}

	
	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("id", id);
		jsonObject.put("title", title);
		if(null != preferential){
			jsonObject.put("preferentiaId", preferential.getId());
			jsonObject.put("preferentiaTitle", preferential.getTitle());
		}
		jsonObject.put("remark", remark);
		jsonObject.put("relayName",relayName);
		jsonObject.put("eid", eid);
		jsonObject.put("type", type);
		jsonObject.put("typeValue", typeValue);
		jsonObject.put("basicFee", basicFee);
		jsonObject.put("startime", startime);
		jsonObject.put("createTime", DateFormatUtils.format(createTime, "yyyy-MM-dd HH:mm:ss"));
		jsonObject.put("updateTime", DateFormatUtils.format(updateTime, "yyyy-MM-dd HH:mm:ss"));
		return jsonObject.toString();
	}

}
